@blackbelt-technology/pi-dashboard-document-converter 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/.pi/skills/document-converter/SKILL.md +79 -0
  2. package/README.md +106 -0
  3. package/engine/.dockerignore +4 -0
  4. package/engine/Dockerfile +75 -0
  5. package/engine/IMAGE_VERSION +1 -0
  6. package/engine/README.md +65 -0
  7. package/engine/VENDOR.md +40 -0
  8. package/engine/build-image.sh +29 -0
  9. package/engine/document_converter/LICENSE +21 -0
  10. package/engine/document_converter/__init__.py +365 -0
  11. package/engine/document_converter/__main__.py +5 -0
  12. package/engine/document_converter/asciidoc_converter.py +534 -0
  13. package/engine/document_converter/cli.py +751 -0
  14. package/engine/document_converter/code_renderer.py +356 -0
  15. package/engine/document_converter/converter.py +928 -0
  16. package/engine/document_converter/cover_page.py +448 -0
  17. package/engine/document_converter/diagram_resizer.py +311 -0
  18. package/engine/document_converter/diagram_sizing.py +357 -0
  19. package/engine/document_converter/docx_reader.py +627 -0
  20. package/engine/document_converter/field_updater.py +277 -0
  21. package/engine/document_converter/font_manager.py +850 -0
  22. package/engine/document_converter/frontmatter_parser.py +644 -0
  23. package/engine/document_converter/graphviz_renderer.py +354 -0
  24. package/engine/document_converter/image_extractor.py +281 -0
  25. package/engine/document_converter/image_style.py +237 -0
  26. package/engine/document_converter/logo_manager.py +1021 -0
  27. package/engine/document_converter/manifest_manager.py +288 -0
  28. package/engine/document_converter/mermaid_renderer.py +371 -0
  29. package/engine/document_converter/meta_mapper.py +398 -0
  30. package/engine/document_converter/pandoc_styles.py +222 -0
  31. package/engine/document_converter/pdf_converter.py +735 -0
  32. package/engine/document_converter/pdf_server.py +283 -0
  33. package/engine/document_converter/plantuml_renderer.py +460 -0
  34. package/engine/document_converter/plantuml_server.py +273 -0
  35. package/engine/document_converter/pyproject.toml +80 -0
  36. package/engine/document_converter/round_trip.py +312 -0
  37. package/engine/document_converter/spacing_applier.py +332 -0
  38. package/engine/document_converter/spacing_config.py +323 -0
  39. package/engine/document_converter/style_extractor.py +420 -0
  40. package/engine/document_converter/svg_embedder.py +294 -0
  41. package/engine/document_converter/system_variables.py +158 -0
  42. package/engine/document_converter/table_formatter.py +450 -0
  43. package/engine/document_converter/template_extractor.py +1334 -0
  44. package/engine/document_converter/template_manager.py +427 -0
  45. package/engine/document_converter/textbox_extractor.py +551 -0
  46. package/engine/document_converter/toc_generator.py +559 -0
  47. package/engine/document_converter/toc_style.py +290 -0
  48. package/engine/document_converter/tree_renderer.py +328 -0
  49. package/engine/document_converter/utils.py +134 -0
  50. package/engine/document_converter/variable_manager.py +394 -0
  51. package/engine/engine_cli.py +371 -0
  52. package/engine/frontmatter_filler/doc-meta.sample.yaml +106 -0
  53. package/engine/frontmatter_filler/fill.py +517 -0
  54. package/engine/markdown_table_profiler/profile.py +442 -0
  55. package/engine/nano-banana-styles.yaml +59 -0
  56. package/engine/tests/test_styled_diagrams.py +109 -0
  57. package/package.json +32 -0
  58. package/src/__tests__/engine.test.ts +72 -0
  59. package/src/__tests__/facade.test.ts +120 -0
  60. package/src/__tests__/integration.test.ts +101 -0
  61. package/src/__tests__/ocr.test.ts +34 -0
  62. package/src/__tests__/provenance.test.ts +89 -0
  63. package/src/__tests__/routing.test.ts +40 -0
  64. package/src/engine.ts +187 -0
  65. package/src/errors.ts +43 -0
  66. package/src/index.ts +179 -0
  67. package/src/ocr.ts +43 -0
  68. package/src/provenance.ts +79 -0
  69. package/src/routing.ts +49 -0
  70. package/src/schema.json +69 -0
  71. package/src/schema.ts +107 -0
  72. package/src/types.ts +90 -0
@@ -0,0 +1,79 @@
1
+ ---
2
+ name: document-converter
3
+ description: Convert documents bidirectionally via the pi-doc-engine facade. Ingest PDF/DOCX/PPTX/XLSX to provenance-stamped Markdown for kb (with selectable OCR). Produce templated DOCX/PDF from Markdown with diagrams (mmdc or styled nano-banana), TOC, cover page, and round-trip extract/edit/merge. Use on requests like "convert this PDF to markdown", "ingest these docs into kb", "make a DOCX from markdown with our template", "render this spec to PDF", "OCR this scanned Hungarian PDF", "edit this DOCX and merge back", "fill frontmatter", "auto-size tables".
4
+ ---
5
+
6
+ # Document Converter
7
+
8
+ TypeScript facade (`@blackbelt-technology/pi-dashboard-document-converter`) over
9
+ the Dockerized `pi-doc-engine` Python engine. **Always call the facade — never
10
+ Python, docling, pandoc, or the nano-banana CLI directly.** The engine is
11
+ quarantined in Docker; the facade is the only call surface.
12
+
13
+ Internals reference: `packages/document-converter/README.md` (facade API),
14
+ `packages/document-converter/engine/README.md` (JSON `docker run` contract).
15
+ Do NOT read the vendored Python under `engine/document_converter/`.
16
+
17
+ ## Prerequisites
18
+
19
+ - Docker available; image built: `cd packages/document-converter && npm run build:image`.
20
+ - Styled diagrams (nano-banana) need `GEMINI_API_KEY` at run time; absent or on
21
+ failure, rendering falls back to mmdc (never hard-fails).
22
+
23
+ ## Two directions
24
+
25
+ ### Ingest — any format → Markdown for kb
26
+
27
+ ```ts
28
+ import { createDocumentConverter } from "@blackbelt-technology/pi-dashboard-document-converter";
29
+ const dc = createDocumentConverter({ image: "pi-doc-engine:0.1.0", stagingDir: "/abs/kb-staging" });
30
+
31
+ await dc.convertToMarkdown("/docs/report.pdf"); // digital PDF (auto: native-first)
32
+ await dc.convertToMarkdown("/docs/scan.pdf", { // scanned HU PDF
33
+ ocr: { mode: "force", lang: ["hungarian", "english"], engine: "tesseract" },
34
+ });
35
+ await dc.convertToMarkdown("/docs/huge.pdf", { tables: "off" }); // escape hatch: skip TableFormer
36
+ ```
37
+
38
+ Output `.md` lands in `stagingDir` with `provenance` frontmatter. Feed kb via its
39
+ existing filesystem source (kb is NOT modified):
40
+
41
+ ```bash
42
+ kb index --source /abs/kb-staging
43
+ kb search "<query>" --source /abs/kb-staging
44
+ ```
45
+
46
+ OCR `lang` takes **canonical names** (`"hungarian"`); the facade maps to per-engine
47
+ codes. A wrong name raises `OCR_LANG_UNSUPPORTED` — no silent empty OCR. Default
48
+ `mode: auto` skips OCR on digital PDFs.
49
+
50
+ ### Produce — Markdown → DOCX/PDF
51
+
52
+ ```ts
53
+ await dc.renderDocx("/spec.md", { output: "/spec.docx", template: "default" });
54
+ await dc.renderDocx("/spec.md", { output: "/spec.docx", nanoBanana: { enabled: true, style: "ros-3d" } });
55
+ await dc.renderPdf("/spec.docx", { output: "/spec.pdf", pageSize: "a4" });
56
+
57
+ const { meta } = await dc.extractForEdit("/in.docx", "/edit.md"); // round-trip
58
+ await dc.mergeBack("/in.docx", "/edit.md", { output: "/out.docx", meta });
59
+ ```
60
+
61
+ Template vars come from frontmatter. Diagrams render with mmdc by default; opt in
62
+ to styled images per-doc via `nanoBanana` (md5-cached `.mermaid-cache/<md5>.png`,
63
+ deterministic, mmdc fallback).
64
+
65
+ ## Frontmatter tooling (the shared bus)
66
+
67
+ ```ts
68
+ await dc.fillFrontmatter(["spec/**/*.md"], { language: "hu" }); // defaults + language packs + globs
69
+ await dc.profileTables(["spec/**/*.md"]); // inject table_profiles width ratios
70
+ ```
71
+
72
+ All stages read/write one unified schema (`./schema`): template vars ·
73
+ `table_profiles` · `nano_banana` · `provenance`.
74
+
75
+ ## Errors
76
+
77
+ Every method rejects with `DocConverterError` (`.code`, `.stderr`, `.exitCode`):
78
+ `UNSUPPORTED_FORMAT`, `OCR_LANG_UNSUPPORTED`, `INGEST_FAILED`, `PRODUCE_FAILED`,
79
+ `DOCKER_UNAVAILABLE`, … Surface `.code` + `.stderr`; do not retry blindly.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # @blackbelt-technology/pi-dashboard-document-converter
2
+
3
+ TypeScript facade over a Dockerized Python document engine (`pi-doc-engine`).
4
+ The **only** call surface for document conversion in the repo. Callers never
5
+ touch Python, docling, pandoc, or the nano-banana CLI.
6
+
7
+ - **Ingest** (feeds kb): PDF/DOCX/PPTX/XLSX → provenance-stamped Markdown.
8
+ - **Produce**: Markdown → templated DOCX/PDF, diagrams, round-trip edit/merge.
9
+ - Engine quarantined in Docker; TS is the contract + orchestrator.
10
+
11
+ ## Facade API
12
+
13
+ ```ts
14
+ import { createDocumentConverter } from "@blackbelt-technology/pi-dashboard-document-converter";
15
+
16
+ const dc = createDocumentConverter({
17
+ image: "pi-doc-engine:0.1.0",
18
+ stagingDir: "/abs/kb-staging",
19
+ });
20
+
21
+ // Ingest -> Markdown with provenance frontmatter (written into stagingDir).
22
+ const { output, provenance } = await dc.convertToMarkdown("/docs/report.pdf", {
23
+ ocr: { mode: "auto", lang: ["hungarian", "english"], engine: "tesseract" },
24
+ });
25
+
26
+ // Produce -> templated DOCX (styled diagrams opt-in via nanoBanana).
27
+ await dc.renderDocx("/docs/spec.md", {
28
+ output: "/out/spec.docx",
29
+ template: "default",
30
+ nanoBanana: { enabled: true, style: "ros-3d" },
31
+ });
32
+
33
+ await dc.renderPdf("/out/spec.docx", { output: "/out/spec.pdf", pageSize: "a4" });
34
+
35
+ // Round-trip.
36
+ const { meta } = await dc.extractForEdit("/in.docx", "/edit.md");
37
+ await dc.mergeBack("/in.docx", "/edit.md", { output: "/out.docx", meta });
38
+
39
+ // Frontmatter tooling over the unified schema.
40
+ await dc.fillFrontmatter(["spec/**/*.md"], { language: "hu" });
41
+ await dc.profileTables(["spec/**/*.md"]);
42
+ ```
43
+
44
+ Every method returns a typed result or rejects with `DocConverterError`
45
+ (`.code`, `.stderr`, `.exitCode`). OCR canonical language names are mapped to
46
+ per-engine codes (`mapOcrCodes`); an unsupported name/engine raises
47
+ `OCR_LANG_UNSUPPORTED` before the engine runs.
48
+
49
+ ## Unified frontmatter schema
50
+
51
+ `./schema` (also `src/schema.json`) is the single contract every stage reads/
52
+ writes: template vars (frontmatter-filler) · `table_profiles` (table profiler) ·
53
+ `nano_banana` (styled diagrams) · `provenance` (ingest, read by kb).
54
+
55
+ ## kb consumption seam (kb is NOT modified)
56
+
57
+ Ingest writes provenance-stamped `.md` into `stagingDir`. kb consumes it via its
58
+ existing `filesystem` source — no kb code change:
59
+
60
+ ```bash
61
+ # Point a kb filesystem source at the staging dir and index it.
62
+ kb index --source /abs/kb-staging
63
+ kb search "deferred tax liabilities" --source /abs/kb-staging
64
+ ```
65
+
66
+ The `provenance` frontmatter (`source_path`, `sha256`, `doc_type`,
67
+ `converted_at`, optional `page`/`slide`) lets kb chunks trace back to the
68
+ originating file. Re-ingesting an unchanged file yields the same `sha256`, so
69
+ staging output is byte-stable (idempotent by hash).
70
+
71
+ ## Templates (runtime-mounted, not baked)
72
+
73
+ DOCX templates are NOT baked into the image — pass `templatesDir` (an absolute
74
+ host dir containing `<template>/template.docx`); the facade bind-mounts it. Keeps
75
+ branded/template assets out of the image and the repo.
76
+
77
+ ## Engine image
78
+
79
+ Built from `engine/` (vendored Python; see `engine/VENDOR.md`):
80
+
81
+ ```bash
82
+ npm run build:image # -> pi-doc-engine:$(cat engine/IMAGE_VERSION)
83
+ ```
84
+
85
+ Heavy (docling ML models + LibreOffice + pandoc + chrome-headless-shell). The
86
+ image runs as root, so an `mmdc` shim injects `--no-sandbox`; opencv needs
87
+ `libgl1`; `@puppeteer/browsers` needs `unzip` (all handled in the Dockerfile).
88
+ See `engine/README.md` for the JSON `docker run` contract.
89
+
90
+ ## Integration test (opt-in)
91
+
92
+ Verified green against `pi-doc-engine:0.1.0`. Build the image, then:
93
+
94
+ ```bash
95
+ DOC_ENGINE_IMAGE=pi-doc-engine:0.1.0 \
96
+ DOC_ENGINE_PDF=/abs/sample.pdf \
97
+ DOC_ENGINE_TEMPLATES=/abs/templates \
98
+ npx vitest run integration
99
+ ```
100
+
101
+ ## Tests
102
+
103
+ ```bash
104
+ npm test # TS facade unit tests (vitest)
105
+ python -m pytest engine/tests -q # engine styled-diagram/cache tests
106
+ ```
@@ -0,0 +1,4 @@
1
+ **/__pycache__/
2
+ **/*.pyc
3
+ **/.venv/
4
+ **/.mermaid-cache/
@@ -0,0 +1,75 @@
1
+ # pi-doc-engine — self-contained Python document engine.
2
+ #
3
+ # Quarantines the vendored Python engine behind a Docker boundary. The TS facade
4
+ # is the only caller; it pipes one JSON request to engine_cli.py over stdin and
5
+ # reads one JSON response from stdout.
6
+ #
7
+ # Build context MUST be this `engine/` directory. The image references NO
8
+ # home-directory (~/Documents) path — everything is copied from the build context.
9
+ #
10
+ # docker build -t pi-doc-engine:<tag> packages/document-converter/engine
11
+ #
12
+ # Bundles: docling (+ EasyOCR/Tesseract/RapidOCR), python-docx/pptx, openpyxl,
13
+ # pandoc, LibreOffice (PDF), @mermaid-js/mermaid-cli (mmdc) + chrome-headless-shell,
14
+ # @the-focus-ai/nano-banana, frontmatter_filler, markdown_table_profiler.
15
+
16
+ FROM python:3.12-slim AS base
17
+
18
+ ENV DEBIAN_FRONTEND=noninteractive \
19
+ PYTHONUNBUFFERED=1 \
20
+ PIP_NO_CACHE_DIR=1 \
21
+ # mmdc/puppeteer use the chrome-headless-shell baked below; never host Chrome.
22
+ PUPPETEER_EXECUTABLE_PATH=/opt/chrome-headless-shell/chrome-headless-shell \
23
+ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
24
+
25
+ # --- System tooling: pandoc, LibreOffice, Tesseract, fonts, Node, headless deps ---
26
+ RUN apt-get update && apt-get install -y --no-install-recommends \
27
+ pandoc \
28
+ libreoffice-writer \
29
+ tesseract-ocr tesseract-ocr-eng tesseract-ocr-hun tesseract-ocr-deu \
30
+ fonts-dejavu fonts-liberation fonts-noto-core \
31
+ curl ca-certificates gnupg unzip \
32
+ libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 \
33
+ libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 \
34
+ libgl1 libglib2.0-0 \
35
+ && curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
36
+ && apt-get install -y --no-install-recommends nodejs \
37
+ && rm -rf /var/lib/apt/lists/*
38
+
39
+ # --- Node CLIs: mmdc + nano-banana, and the pinned chrome-headless-shell ---
40
+ RUN npm install -g @mermaid-js/mermaid-cli @the-focus-ai/nano-banana \
41
+ && npx --yes @puppeteer/browsers install chrome-headless-shell@stable \
42
+ --path /opt/chrome-headless-shell-dl \
43
+ && ln -s "$(find /opt/chrome-headless-shell-dl -name chrome-headless-shell -type f | head -1 | xargs dirname)" \
44
+ /opt/chrome-headless-shell
45
+
46
+ # --- Python engine deps (docling pulls OCR/ML model libs) ---
47
+ RUN pip install \
48
+ "docling" \
49
+ "python-docx>=1.0.0" "python-pptx>=0.6.23" "openpyxl>=3.1" \
50
+ "pypandoc>=1.11" "Pillow>=10.0.0" \
51
+ "ruamel.yaml>=0.18" "PyYAML>=6.0" \
52
+ "easyocr" "rapidocr-onnxruntime"
53
+
54
+ # --- mmdc shim: force --no-sandbox + baked chrome (container runs as root) ---
55
+ # Vendored mermaid_renderer.py calls bare `mmdc` with only `-c`; it never passes
56
+ # a puppeteer config, so Chrome refuses to launch as root. A shim earlier in PATH
57
+ # (/usr/local/bin precedes /usr/bin) injects `-p` without editing vendored code.
58
+ RUN printf '{"executablePath":"%s","args":["--no-sandbox","--disable-gpu","--disable-dev-shm-usage"]}\n' \
59
+ "$PUPPETEER_EXECUTABLE_PATH" > /opt/puppeteer.json \
60
+ && printf '#!/bin/sh\nexec node /usr/lib/node_modules/@mermaid-js/mermaid-cli/src/cli.js -p /opt/puppeteer.json "$@"\n' \
61
+ > /usr/local/bin/mmdc \
62
+ && chmod +x /usr/local/bin/mmdc
63
+
64
+ # --- Vendored engine (the ONLY app source; no home-dir path) ---
65
+ WORKDIR /engine
66
+ COPY . /engine/
67
+
68
+ # Pre-warm docling model artifacts so first run does not download at runtime.
69
+ # (Best-effort: skip silently if offline at build time.)
70
+ RUN python -c "from docling.utils.model_downloader import download_models; download_models()" || true
71
+
72
+ ENV PYTHONPATH=/engine
73
+
74
+ # JSON-over-stdin/stdout contract. `docker run -i pi-doc-engine < req.json`.
75
+ ENTRYPOINT ["python", "/engine/engine_cli.py"]
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,65 @@
1
+ # pi-doc-engine
2
+
3
+ Self-contained Docker image wrapping the vendored Python document engine. The TS
4
+ facade (`packages/document-converter`) is the only caller. No host Python.
5
+
6
+ ## Build
7
+
8
+ ```bash
9
+ ./build-image.sh # pi-doc-engine:$(cat IMAGE_VERSION)
10
+ IMAGE_TAG=pi-doc-engine:dev ./build-image.sh
11
+ ```
12
+
13
+ Build context = this directory. A guard fails the build if any vendored `*.py`
14
+ references a `~/Documents` / source-skill path.
15
+
16
+ ## Invocation contract (stdin/stdout JSON)
17
+
18
+ One request object on **stdin**, one response object on **stdout**, exit code
19
+ signals success.
20
+
21
+ ```bash
22
+ docker run --rm -i \
23
+ -v "$WORKDIR:$WORKDIR" -w "$WORKDIR" \
24
+ -e GEMINI_API_KEY \
25
+ pi-doc-engine:0.1.0 < request.json > response.json
26
+ ```
27
+
28
+ - All paths in the request/response are **container paths**. The facade bind-mounts
29
+ a work dir and rewrites host→container paths before calling.
30
+ - `GEMINI_API_KEY` is injected at `docker run` time only (never baked). Absent →
31
+ styled diagrams fall back to mmdc.
32
+
33
+ ### Request
34
+
35
+ ```json
36
+ { "command": "<name>", "...": "params" }
37
+ ```
38
+
39
+ | command | params | result |
40
+ |---|---|---|
41
+ | `convertToMarkdown` | `input`, `output?`, `ocr{mode,engine,codes[]}`, `tables` | `{markdown, output}` |
42
+ | `renderDocx` | `input`, `output`, `template?`, `templatesDir?`, `language?`, `nano_banana{enabled,style}?`, `cacheDir?` | `{output}` |
43
+ | `renderPdf` | `input`, `output`, `pageSize?`, `template?` | `{output}` |
44
+ | `extractForEdit` | `input`, `output` | `{output, meta}` |
45
+ | `mergeBack` | `original`, `edited`, `output`, `meta?` | `{output}` |
46
+ | `fillFrontmatter` | `paths[]`, `mode?`, `config?`, `language?`, `set[]?`, `apply?` | `{stdout}` |
47
+ | `profileTables` | `paths[]`, `apply?`, `percentile?`, `smoothing?` | `{stdout}` |
48
+
49
+ OCR `codes[]` are **per-engine** codes (EasyOCR `hu`, Tesseract `hun`). The TS
50
+ facade maps canonical language names → codes before calling, so a wrong code can
51
+ never silently produce empty OCR.
52
+
53
+ ### Response
54
+
55
+ ```json
56
+ { "ok": true, "...": "result fields" }
57
+ { "ok": false, "error": { "code": "INGEST_FAILED", "message": "...", "stderr": "..." } }
58
+ ```
59
+
60
+ Exit codes: `0` ok · `1` engine error · `2` bad/unknown request. The facade maps
61
+ non-zero exits + the `error.code` to typed errors.
62
+
63
+ ## Vendored sources
64
+
65
+ See `VENDOR.md` for upstream paths, versions, and refresh procedure.
@@ -0,0 +1,40 @@
1
+ # Vendored engine provenance
2
+
3
+ This directory carries a **committed copy** of the Python document-processing
4
+ engine. The `pi-doc-engine` Docker image builds **only** from this copy. No
5
+ runtime path references `~/Documents` or any home directory.
6
+
7
+ "Keep Python, wrap in TS": these are vendored verbatim, not paraphrased. Refresh
8
+ by re-copying from the upstream sources below and updating this record.
9
+
10
+ ## Sources
11
+
12
+ | Vendored path | Upstream source | Version | Copied | sha256 (anchor file) |
13
+ |---|---|---|---|---|
14
+ | `document_converter/` | `~/Documents/.gemini/skills/document-conversion/src/document_converter/` | pyproject `0.6.0` / `__init__.__version__` `0.5.0` | 2026-06-24 | `pyproject.toml` `b905795412a59482a1d09e3e69ded12d4f85f7691547d68cdd3179883360d2c1` |
15
+ | `frontmatter_filler/fill.py` | `~/Documents/.agents/skills/frontmatter-filler/scripts/fill.py` | mtime 2026-04-22 (no version tag) | 2026-06-24 | `574e13c8e21068d2f88ecc9d0414fce54a28019a7ffb69ad83e2f870f5d93fa2` |
16
+ | `markdown_table_profiler/profile.py` | `~/Documents/.agents/skills/markdown-table-profiler/scripts/profile.py` | mtime 2026-04-22 (no version tag) | 2026-06-24 | `a0501eb8b54ba60c8e8f703427155450994cc41d920f62df451e85a91fe1c3a6` |
17
+
18
+ None of the upstream sources are under git, so commit hashes are unavailable;
19
+ anchor-file sha256 + copy date establish traceability.
20
+
21
+ ## Runtime dependencies (installed by the image, NOT vendored as source)
22
+
23
+ - `document_converter` (pyproject): `pypandoc>=1.11`, `python-docx>=1.0.0`, `Pillow>=10.0.0`
24
+ - `frontmatter_filler/fill.py` (PEP 723 inline): `ruamel.yaml>=0.18`
25
+ - `markdown_table_profiler/profile.py` (PEP 723 inline): none
26
+ - Ingest engine: `docling` (+ OCR engines), installed via pip in the Dockerfile
27
+ - System tooling: `pandoc`, Gotenberg, `@mermaid-js/mermaid-cli` (mmdc),
28
+ chrome-headless-shell, `@the-focus-ai/nano-banana`
29
+
30
+ ## Excluded from vendoring
31
+
32
+ `__pycache__/`, `*.pyc`, `.venv/`, `tests/`, `examples/`, `hooks/`, `workflows/`
33
+ — not needed to build or run the engine inside the image.
34
+
35
+ ## Engine command boundary
36
+
37
+ `engine/engine_cli.py` is the **only** entry the TypeScript facade invokes. It
38
+ reads one JSON request on stdin, dispatches to the vendored modules + docling,
39
+ writes one JSON response on stdout, and maps failures to non-zero exit codes.
40
+ See `engine/engine_cli.py` for the contract.
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env bash
2
+ # Build the pi-doc-engine image from the in-repo vendored engine copy.
3
+ #
4
+ # ./build-image.sh # build pi-doc-engine:<IMAGE_VERSION>
5
+ # IMAGE_TAG=pi-doc-engine:dev ./build-image.sh
6
+ #
7
+ # The build context is THIS directory only — the image must reference no
8
+ # home-directory path. A guard below fails the build if a ~/Documents reference
9
+ # leaked into the vendored source.
10
+ set -euo pipefail
11
+
12
+ ENGINE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13
+ IMAGE_VERSION="$(cat "$ENGINE_DIR/IMAGE_VERSION")"
14
+ IMAGE_TAG="${IMAGE_TAG:-pi-doc-engine:${IMAGE_VERSION}}"
15
+
16
+ # --- Guard: no home-dir / ~/Documents path may leak into the runtime Python ---
17
+ # Scoped to *.py runtime source (the only code that ships); meta files (this
18
+ # script, Dockerfile, VENDOR.md) legitimately name the pattern in prose.
19
+ GUARD_PAT='~/Documents|/Users/[^/]+/Documents|\.gemini/skills|\.agents/skills'
20
+ if grep -RInE "$GUARD_PAT" "$ENGINE_DIR" --include='*.py' \
21
+ --exclude-dir=__pycache__ >/dev/null 2>&1; then
22
+ echo "ERROR: home-dir / source-skill path reference found in engine Python:" >&2
23
+ grep -RInE "$GUARD_PAT" "$ENGINE_DIR" --include='*.py' --exclude-dir=__pycache__ >&2
24
+ exit 1
25
+ fi
26
+
27
+ echo "Building ${IMAGE_TAG} from ${ENGINE_DIR} ..."
28
+ docker build -t "${IMAGE_TAG}" "${ENGINE_DIR}"
29
+ echo "Built ${IMAGE_TAG}"
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Test Automation Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.